/**
人员选择树
types   checkbox 多选, radio 单选
selectuseronly
TreeAction.java 提供不同的选择方式
*/
//控件出发对象
//表单对象
var inputOBJ;
//显示对象
var viewObj;



/**
*添加驾驶员
*/
function add_jsy(index){
	var url = context + "/app/jsy.do?method=list&type=select&index=" + index;
	dialog(url,true,"选择驾驶员",700,450);
}
/**
*添加车辆
*/
function add_clxx(index){ 
	var url = context + "/app/clxx.do?method=list&type=select&index=" + index;
	dialog(url,true,"选择车辆",700,450);
}
/**
*添加车辆及驾驶员
*/
function add_cl_jsy(){
	var txt="";
	cl_jsy_num = cl_jsy_num + 1;
 	txt += " <div id='" + cl_jsy_num + "' dtype='cl_jsy_obj' dname='" + "" + "'>";
    txt += "<table border='0' width='100%'><tr>";
    
    txt += "<input type=hidden  id='clxx_id" + cl_jsy_num + "' value='" + "" + "' size=2 /></td>";
    txt += "<td width='25%'><input readonly type=text class='box3' id='clxx_name" + cl_jsy_num + "' value='" + "" + "' size=20 /></td>";
    txt += "<td width='20%'><a herf='#' onclick='add_clxx(" + cl_jsy_num + ")'>指派车辆</a></td>";
    
     txt += "<input type=hidden  id='jsy_id" + cl_jsy_num + "' value='" + "" + "' size=2 /></td>";
    txt += "<td width='25%'><input readonly type=text class='box3' id='jsy_name" + cl_jsy_num + "' value='" + "" + "' size=20 /></td>";
    txt += "<td width='20%'><a herf='#' onclick='add_jsy(" + cl_jsy_num + ")'>指派驾驶员</a></td>";
   
    txt += "<td width='10%'><span title='删除' style='cursor:hand;' onclick=\"javascript:handleRemove('" + cl_jsy_num + "');\">×</span></td>";
    txt += "</tr></table>";
    
    document.getElementById("fs_clsqd").innerHTML = document.getElementById("fs_clsqd").innerHTML + txt;
}

function selectPeople(obj,types,ids){
    inputOBJ = obj;
    inputOBJID = ids;
    
    var url = context + "/system/tree.do?method=selectuseronly&type=" + types + "&autoselect=false";

    if(document.getElementById(ids)){
       var s = document.getElementById(ids).value.split(",");
       dftids = "";
       for(var i=0;i<s.length;i++){
          if(s[i] != ""){
             dftids += "u" + s[i] + ",";
          }
       }
       url += "&defaultnode=" + dftids;
    }
    
    dialog(url,true,"选择人员",300,350);
}
function selectCompany(obj,types,ids){
    inputOBJ = obj;
    inputOBJID = ids;
    var url = context + "/system/tree.do?method=selectgrouptree&type=" + types + "&autoselect=false";

    if(document.getElementById(ids)){
       var s = document.getElementById(ids).value.split(",");
       dftids = "";
       for(var i=0;i<s.length;i++){
          if(s[i] != ""){
             dftids += "u" + s[i] + ",";
          }
       }
       url += "&defaultnode=" + dftids;
    }
    
    dialog(url,true,"选择公司部门",300,350);
}
/**
人员选择回调函数
ids id字符串
names 中文名称字符串
types 未知
**/ 
  function responseResult(ids,names,types){
  	 inputOBJ.value = names;
  	 if(document.getElementById(inputOBJID)){
  	    document.getElementById(inputOBJID).value = ids.replace(/u/g,"");
  	 }
  	 closeDialog();
  }     
   /*保存提交*/
   function handleSubmit(){
     if(isblank(document.form1.clsqd_ycdw)){
        alert("请填写用车单位");
     }else if(confirm("确定提交")){
     //生成车辆驾驶员隐藏域
        initObj();
        document.form1.submit();
     }
   }
   
   
   /*删除车辆驾驶员*/
   function handleRemove(id){
      document.getElementById(id).removeNode(true);
   }
    /**生成车辆驾驶员隐藏域*/
    function initObj(){ 
     var countO = "";
     var ro = document.getElementsByTagName("DIV");
    
     for(var i=0;i<ro.length;i++){
        if(ro[i].getAttribute("dtype") == "cl_jsy_obj"){
           var id = ro[i].id;
           var clxx_id = document.getElementById("clxx_id"+id).value;
           var jsy_id = document.getElementById("jsy_id"+id).value;
           if(clxx_id!=""&clxx_id!=null&jsy_id!=""&jsy_id!=null){
	           createHidden("clsqd_id_" + i,"");
	           createHidden("clxx_id_" + i,clxx_id);
	           createHidden("jsy_id_" + i,jsy_id);
	           countO += i + ",";
           }
        }
     }
      
     createHidden("countO",countO.substring(0,countO.length -1));
   }
   
